package com.fanshuai.soring.boot.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Slf4j
public class LogFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String path = request.getRemoteHost() + "/" + request.getRequestURI();
        Map<String, String[]> params = request.getParameterMap();

        filterChain.doFilter(request, response);
        log.info("http request, path={}, params={}", path, params);
    }
}
